import { PolygonGeometry, PolygonHierarchy, Cartesian3,EllipsoidSurfaceAppearance, Primitive,CallbackProperty, GeometryInstance,Material} from 'cesium';
import waterimg from './waterNormals.jpg'
const waterLayer = function(arrayPoints,holes,height) {
    var polygon
    this.height = height
    var self = this
    if(holes && holes.length>0){
        polygon = new PolygonGeometry({
            polygonHierarchy : new PolygonHierarchy(Cartesian3.fromDegreesArray(arrayPoints),new PolygonHierarchy(Cartesian3.fromDegreesArray(holes[0]))),
            extrudedHeight: 30
          
        });
    }else{
        polygon = new PolygonGeometry({
            polygonHierarchy : new PolygonHierarchy(Cartesian3.fromDegreesArray(arrayPoints)),
            extrudedHeight: 3
           
        });
    }
    this.River = new Primitive({
        geometryInstances : new GeometryInstance({
            geometry :polygon
        }),
        appearance : new EllipsoidSurfaceAppearance({
//             fragmentShaderSource:'varying vec3 v_positionMC;\nvarying vec3 v_positionEC;\nvarying vec2 v_st;\nvoid main()\n{\nczm_materialInput materialInput;\nvec3 normalEC = normalize(czm_normal3D * czm_geodeticSurfaceNormal(v_positionMC, vec3(0.0), vec3(1.0)));\n#ifdef FACE_FORWARD\nnormalEC = faceforward(normalEC, vec3(0.0, 0.0, 1.0), -normalEC);\n#endif\nmaterialInput.s = v_st.s;\nmaterialInput.st = v_st;\nmaterialInput.str = vec3(v_st, 0.0);\nmaterialInput.normalEC = normalEC;\nmaterialInput.tangentToEyeMatrix = czm_eastNorthUpToEyeCoordinates(v_positionMC, materialInput.normalEC);\nvec3 positionToEyeEC = -v_positionEC;\nmaterialInput.positionToEyeEC = positionToEyeEC;\nczm_material material = czm_getMaterial(materialInput);\n#ifdef FLAT\ngl_FragColor = vec4(material.diffuse + material.emission, material.alpha);\n#else\ngl_FragColor = czm_phong(normalize(positionToEyeEC), material);\
// gl_FragColor.a=0.5;\n#endif\n}\n'
        }),
        show : true
    });
    var River1_Material = new Material({
        fabric : {
            type : 'Water',
            uniforms : {
                baseWaterColor:{
                    alpha: 0.8,
                    blue: 0.4,
                    green: 0.2,
                    red:  0.1,
                },
                normalMap:waterimg,
                frequency: 2000.0,
                animationSpeed: 0.05,
                amplitude: 12
            }
        }
    });
    this.River.appearance.material = River1_Material;
}
waterLayer.prototype={
    addTo:function(scene){
        // scene.primitives.remove(this.River);
        scene.primitives.add(this.River); //添加到场景
    },
    goto:function(){

    }
}
export default waterLayer